const mongoose = require("mongoose");

//待发货数据获取
module.exports.getOrderWaiting_3 = async function({pageSize, currentPage}){
    let totalCount = await mongoose.model("ordersModel").find({status: "待发货"}).countDocuments();
    let totalPage = Math.ceil(totalCount/pageSize);
    let order = await mongoose.model("ordersModel").find({status: "待发货"}).limit(pageSize-0).skip((currentPage-1)*pageSize); //.populate("userId").populate("orderGoodsId")
    return {totalCount, pageSize, currentPage, totalPage, order };
}

// 修改发货状态
module.exports.modifyOrderStatus_3 = async function(data){
    console.log(data);
    let result = await mongoose.model("ordersModel").updateOne(data, {status: "已发货"});
    console.log(result);
    return result;
}

// 获取所有数据
module.exports.getAllOrder_3 = async function({pageSize, currentPage}){
    let totalCount = await mongoose.model("ordersModel").find().countDocuments();
    let totalPage = Math.ceil(totalCount/pageSize);
    let order = await mongoose.model("ordersModel").find().limit(pageSize-0).skip((currentPage-1)*pageSize); //.populate("userId").populate("orderGoodsId")
    return {totalCount, pageSize, currentPage, totalPage, order };
}